<?php
// +----------------------------------------------------------------------
// | 有小象汇 自研正版源码 赋能开发者
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 http://www.uxphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 有小象汇并不是自由软件，未经许可不能去掉有小象汇相关版权
// +----------------------------------------------------------------------
// | Author:  有小象汇
// +----------------------------------------------------------------------

namespace app\dao\car;


use app\dao\BaseDao;
use app\model\car\CarHoliday;

/**
 * Class CarHolidayDao
 * @package app\dao\car
 */
class CarHolidayDao extends BaseDao
{
    protected function setModel(): string
    {
        return CarHoliday::class;
    }

    /**
     * 列表
     * @param array $where
     * @param string $field
     * @param int $page
     * @param int $limit
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getList(array $where = [], string $field = '*', int $page, int $limit){
        $model = $this->getModel()->alias('h')->where('h.is_del',0);
        $model->join('base_place p','p.id=h.store_id','left');
        $model->field('h.*,p.title as place_name');
        if(isset($where['store_id']) && $where['store_id']){
            $model->where('p.id','=',$where['store_id']);
        }
        if(isset($where['title']) && $where['title']){
            $model->where('h.title','like','%'.$where['title'].'%');
        }
        $count = $model->count();
        $list = $model->order('h.id desc')->page($page,$limit)->select()->toArray();
        return compact('count','list');
    }
}
